<!---->
<template>
    <div class="page_editzhengdi">
        <common-header :title="'征地信息编辑'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="btn-save" @click="saveLandTransferInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <x-input title="征地面积(亩)" type="number" v-model="info.landarea"
                             placeholder="请输入征地面积(亩)">
                    </x-input>
                </div>
                <div class="item-item">
                    <datetime title="征地时间" placeholder="请选择征地时间" v-model="expropriationtime"></datetime>
                </div>
                <div class="item-item">
                    <x-input title="补偿金额(元)" type="number" v-model="info.expropriationoffset"
                             placeholder="请输入补偿金额(元)">
                    </x-input>
                </div>
                <div class="item-item">
                    <datetime :min-year="1900" title="补偿发放时间" placeholder="请选择补偿发放时间" v-model="offsetsenttime"></datetime>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'
    import {XInput, Selector, Datetime} from 'vux'
    import {checkNumber} from '../../utils/validate'
    export default {
        name: "editzhengdi",
        components: {
            XInput, Selector, Datetime
        },
        data() {
            return {
                id: this.$route.query.id,
                expropriationtime: this.$route.query.expropriationtime,
                offsetsenttime: this.$route.query.offsetsenttime,
                info: {
                    familyid: this.$route.query.familyid,
                    villagecode: this.$route.query.villagecode,
                    transfertype: 3,
                    landarea: this.$route.query.landarea,
                    expropriationtime: '',
                    offsetsenttime: '',
                    expropriationoffset: this.$route.query.expropriationoffset,
                },
            }
        },

        watch: {},
        methods: {
            // 保存zheng地信息
            saveLandTransferInfo() {
                let param = {
                    landarea: '请输入正确征地面积（数字类型且最多保留两位小数）',
                    expropriationtime: '请选择征地时间',
                    expropriationoffset: '请输入正确补偿金额（数字类型且最多保留两位小数）',
                    offsetsenttime: '请选择补偿发放时间',
                }

                for (let i in param) {

                    if (i === 'expropriationtime') {
                        if (!this.expropriationtime) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    } else if (i === 'offsetsenttime') {
                        if (!this.offsetsenttime) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    } else {
                        if (!this.info[i]) {
                            this.$vux.toast.show({
                                text: param[i],
                                type: 'text',
                                position: 'middle',
                            })
                            return;
                        }
                    }

                }


                if(!checkNumber(this.info.landarea,'征地面积')){
                    return
                }
                if(!checkNumber(this.info.expropriationoffset,'补偿金额')){
                    return
                }

                if (this.id) {
                    this.info = Object.assign(this.info, {id: this.id})
                }
                this.info.expropriationtime = this.expropriationtime + ' ' + '00:00:00';
                this.info.offsetsenttime = this.offsetsenttime + ' ' + '00:00:00';
                let _param = this.$tools.invokeUAF('resident/saveLandTransferInfo', this.info)
                resident.saveLandTransferInfo(_param).then(res => {
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
    .page_editzhengdi {

    }

</style>
